package com.example.demo;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

import java.util.Arrays;
import java.util.Set;

public class MyTaskListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        String assignee = delegateTask.getAssignee();
        String eventName = delegateTask.getEventName();
        String name = delegateTask.getName();
        String processInstanceId = delegateTask.getProcessInstanceId();
        System.out.println("审核人："+assignee);
        System.out.println("事件名称："+eventName);
        System.out.println("任务名称："+name);
        System.out.println("流程实例ID："+processInstanceId);
        Set<String> variableNames = delegateTask.getVariableNames();
        for (String key : variableNames) {
            Object value = delegateTask.getVariable(key);
            System.out.println(key + " = " + value);
        }
        //动态添加审核人
        String[] empLoyees = {"xiaoshuai","dashuai"};
        delegateTask.addCandidateUsers(Arrays.asList(empLoyees));
    }
}
